import 'package:flutter_house_manager/constants/index.dart';
import 'package:shared_preferences/shared_preferences.dart';

class TokenManager {
  //1、获取实例
  Future<SharedPreferences> _getInstance() {
    return SharedPreferences.getInstance();
  }

  //2、存储token
  setToken(String token) async {
    final prefs = await _getInstance();
    prefs.setString(GlobalVariable.TOKEN_KEY, token);
  }

  //3、获取token
  Future<String?> getToken() async {
    final prefs = await _getInstance();
    return prefs.getString(GlobalVariable.TOKEN_KEY);
  }

  //4、删除token
  Future<bool> removeToken() async {
    final prefs = await _getInstance();
    return prefs.remove(GlobalVariable.TOKEN_KEY);
  }
}

final TokenManager tokenManager = TokenManager();
